<!doctype html>
<html lang="en"><head>
    <meta charset="utf-8">
    <title>后台管理--写文章</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!--Ueditor-->

    <script type="text/javascript" charset="utf-8" src="<?php echo SITE_URL.'ueditor/'; ?>ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<?php echo SITE_URL.'ueditor/'; ?>ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="<?php echo SITE_URL.'ueditor/'; ?>lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript" charset="utf-8" src="<?php echo SITE_URL.'ueditor/'; ?>jquery.min.js"></script>
    <!--Ueditor End-->

    <!--link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'-->
    <link rel="stylesheet" type="text/css" href="<?php echo VIEW.'admin/'?>lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="<?php echo VIEW.'admin/'?>lib/font-awesome/css/font-awesome.css">

    <script src="<?php echo VIEW.'admin/'?>lib/jquery-1.11.1.min.js" type="text/javascript"></script>

    <script src="<?php echo VIEW.'admin/'?>lib/jQuery-Knob/js/jquery.knob.js" type="text/javascript"></script>

    <link rel="stylesheet" type="text/css" href="<?php echo VIEW.'admin/'?>stylesheets/theme.css">
    <link rel="stylesheet" type="text/css" href="<?php echo VIEW.'admin/'?>stylesheets/premium.css">

</head>
<body class="theme-blue">

<!-- header white -->
<style type="text/css">
    #line-chart {
        height:300px;
        width:800px;
        margin: 0px auto;
        margin-top: 1em;
    }
    .navbar-default .navbar-brand, .navbar-default .navbar-brand:hover {
        color: #fff;
    }
</style>

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="../assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">


<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->

<!--<![endif]-->

<div class="navbar navbar-default" role="navigation">
    <div class="navbar-header">
        <a class="navbar-brand" href="<?php echo SITE_URL.'index.php/admin';?>">后台管理</a>
    </div>

    <div class="navbar-collapse collapse" style="height: 1px;">
        <ul id="main-menu" class="nav navbar-nav navbar-right">
            <li class="dropdown hidden-xs">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <span class="glyphicon glyphicon-user padding-right-small" style="position:relative;top: 3px;"></span><?=$username?><i class="fa fa-caret-down"></i>
                </a>

                <ul class="dropdown-menu">
                    <li><a href="#">我的信息</a></li>
                    <li class="divider"></li>
                    <li class="dropdown-header">管理界面</li>
                    <li><a href="<?php echo SITE_URL.'index.php/admin/logout';?>">退出</a></li>
                </ul>
            </li>
        </ul>

    </div>
</div>


<div class="sidebar-nav">
    <ul>
        <li><a href="#" data-target=".dashboard-menu" class="nav-header" data-toggle="collapse"><i class="fa fa-fw fa-dashboard"></i> 仪表盘<i class="fa fa-collapse"></i></a>
        </li>
        <li><ul class="dashboard-menu nav nav-list collapse in">
                <li><a href="<?php echo SITE_URL.'index.php/admin';?>"><span class="fa fa-caret-right"></span> 主界面</a></li>
                <li ><a href="<?php echo SITE_URL.'index.php/article/editor';?>"><span class="fa fa-caret-right"></span> 写文章</a></li>
                <li ><a href="<?php echo SITE_URL.'index.php/article/lists';?>"><span class="fa fa-caret-right"></span>文章列表</a></li>
                <!-- 暂时不用 -->
                <!--li ><a href="#"><span class="fa fa-caret-right"></span> 用户列表</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 用户信息</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 媒体</a></li-->
            </ul></li>

        <li data-popover="true" rel="popover" data-placement="right"><a href="#" data-target=".premium-menu" class="nav-header collapsed" data-toggle="collapse"><i class="fa fa-fw fa-fighter-jet"></i> 高级功能<i class="fa fa-collapse"></i></a></li>
        <!--li><ul class="premium-menu nav nav-list collapse">
                <li ><a href="#"><span class="fa fa-caret-right"></span> 升级用户</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 插件</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 更新时间列表</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 媒体列表</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 更多工具</a></li>
            </ul></li!-->

        <li><a href="#" data-target=".accounts-menu" class="nav-header collapsed" data-toggle="collapse"><i class="fa fa-fw fa-briefcase"></i>账户</a></li>
        <li><ul class="accounts-menu nav nav-list collapse">
                <li ><a href="<?php echo SITE_URL.'index.php/admin/accountinfo';?>"><span class="fa fa-caret-right"></span>账户信息</a></li>
                <li ><a href="<?php echo SITE_URL.'index.php/admin/logout';?>"><span class="fa fa-caret-right"></span>退出</a></li>
            </ul></li>

        <li><a href="#" data-target=".legal-menu" class="nav-header collapsed" data-toggle="collapse"><i class="fa fa-fw fa-legal"></i>法律信息<i class="fa fa-collapse"></i></a></li>
        <li><ul class="legal-menu nav nav-list collapse">
                <li ><a href="#"><span class="fa fa-caret-right"></span> 隐私权政策</a></li>
                <li ><a href="#"><span class="fa fa-caret-right"></span> 条款与条件</a></li>
            </ul></li>

        <li><a href="#" class="nav-header"><i class="fa fa-fw fa-question-circle"></i>帮助</a></li>
        <li><a href="#" class="nav-header"><i class="fa fa-fw fa-comment"></i>问与答</a></li>
    </ul>
</div>

<div class="content">
    <div class="header">
        <div class="stats">
            <!--p class="stat"><span class="label label-info">5</span> 通知</p>
            <p class="stat"><span class="label label-success">27</span> 任务</p>
            <p class="stat"><span class="label label-danger">15</span> 过期</p-->
        </div>

        <h1 class="page-title">仪表盘</h1>
        <ul class="breadcrumb">
            <li><a href="<?php echo SITE_URL.'index.php/admin';?>">管理主页</a> </li>
            <li class="active">写文章</li>
        </ul>

    </div>
    <div class="main-content">

        <div class="row">
            <div class="col-md-11 ">
                <label>标题</label><input class="input" type="text" id="articletitle" value="<?php if(isset($blog)) echo $blog->title;?>">
                <select id="sortid">
                    <?php
                        if(!isset($sort))
                        {
                            $sort = 0;
                        }
                        for($i=0;$i<count($sort);$i++)
                        {
                            if(isset($blog))
                            {
                                if($sort[$i]['sid'] == $blog->sortid)
                                {
                                    echo sprintf('<option value ="%s" selected="selected">%s</option>',$sort[$i]['sid'],$sort[$i]['sortname']);
                                }
                                else{
                                    echo sprintf('<option value ="%s">%s</option>',$sort[$i]['sid'],$sort[$i]['sortname']);
                                }
                            }
                            else{
                                echo sprintf('<option value ="%s">%s</option>',$sort[$i]['sid'],$sort[$i]['sortname']);
                            }

                        }
                    ?>
                </select>
                <input type="date" style="padding:0; line-height: 12px;"id="date" value="<?php if(isset($blog)) echo date("Y-m-d",$blog->date);?>">

                <script id="myEditor" type="text/plain" style="height:500px;"></script>
                <script type="text/javascript">
                    var ue = UE.getEditor('myEditor');
                    //设置update
                    ue.ready(function() {
                        //设置编辑器的内容
                        //ue.setContent('hello');
                        //获取html内容，返回: <p>hello</p>
                        //var html = ue.getContent();
                        //获取纯文本内容，返回: hello
                        //var txt = ue.getContentTxt();
                        <?php if(isset($blog)) echo sprintf("ue.execCommand('inserthtml', '%s')",$blog->content);?>
                        //ue.execCommand( 'inserthtml', '<b>aaaa</b>');
                    });

                    //editor.render("myEditor");
                </script>
                <button id="b">提交</button>
            </div>
        </div>



    </div>
    <footer>
        <p style="display:none" id="qid"><?php if(isset($blog)) echo $blog->qid;?></p>
        <hr>

        <!-- Purchase a site license to remove this link from the footer: http://www.portnine.com/bootstrap-themes -->
        <p class="pull-right">YZ Studio</a></p>
        <p>© <?= date('Y') ?> <a href="#" target="_blank">规划处</a></p>
    </footer>
</div>


<script src="<?php echo VIEW.'admin/'?>lib/bootstrap/js/bootstrap.js"></script>
<script>
    $(document).ready(function(){
        $("#b").click(function(){
            //进行三个用户填写内容判断
            if($("#articletitle").val() == "")
            {
                alert("您还未填写标题");
                return ;
            }
            if($("#date").val() == "")
            {
                alert("您还未填写日期");
                return ;
            }
            if(ue.hasContents() == false)
            {
                alert("您的文章是空的");
                return ;
            }
            /*else
            {
                alert(UE.getEditor('myEditor').getContent());
            }*/
            if($("#qid").text() == "")
            {//add
                $.post("<?php echo SITE_URL.'index.php/article/addarticle' ?>",
                    {
                        name:"Donald Duck",
                        title:$("#articletitle").val(),
                        sortid:$("#sortid  option:selected").val(),
                        date:$("#date").val(),
                        content:UE.getEditor('myEditor').getContent()
                    },
                    function(data,status){
                        //alert(data);
                        console.log(data);
                        if(data == "ok")
                        {
                            alert("文章提交成功");
                            location.reload();
                        }
                        else
                        {
                            alert('提交失败\n请联系技术人员！');
                        }
                        //alert($("#articletitle").val());
                    });


            }else
            {//update
                $.post("<?php echo SITE_URL.'index.php/article/updatearticle' ?>",
                    {
                        name:"Donald Duck",
                        title:$("#articletitle").val(),
                        sortid:$("#sortid  option:selected").val(),
                        date:$("#date").val(),
                        content:UE.getEditor('myEditor').getContent(),
                        qid:$("#qid").text()
                    },
                    function(data,status){
                        //alert(data);
                        console.log(data);
                        if(data == "ok")
                        {
                            alert("文章更新成功");
                            //location.reload();
                        }
                        else
                        {
                            alert('提交失败\n请联系技术人员！');
                        }
                        //alert($("#articletitle").val());
                    });
            }
            /**/
            //alert($("#qid").text());
            //alert(UE.getEditor('myEditor').getContent());

            //console.log(UE.getEditor('myEditor').getContent());
        });
    });
</script>

</body>
</html>
